//
//  TubiaoViewController_1.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/22.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "TubiaoViewController_1.h"

#import "PNChartDelegate.h"
#import "PNChart.h"

@interface TubiaoViewController_1 () <PNChartDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;

//
@property (nonatomic, strong) UIView * view_bg1;
@property (nonatomic, strong) UIView * view_bg2;
@property (nonatomic, strong) UIView * view_bg3;

@property (nonatomic) PNLineChart * lineChart1;
@property (nonatomic) PNLineChart * lineChart2;
@property (nonatomic) PNLineChart * lineChart3;

@end

@implementation TubiaoViewController_1

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _lblTitle.text = [NSString stringWithFormat:@"数据访问量"];
    _lblTitle.font = [UIFont systemFontOfSize:20];
    
    [self addLeftButton:@"fanhui@2x.png"];
    
    [self addRightButton:@"shuaxin@2x.png"];
}

//左返回
- (void)clickLeftButton:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//刷新
- (void)clickRightButton:(UIButton *)sender
{
    self.lineChart1.displayAnimated = YES;
    [self.lineChart1 strokeChart];
    
    self.lineChart2.displayAnimated = YES;
    [self.lineChart2 strokeChart];
    
    self.lineChart3.displayAnimated = YES;
    [self.lineChart3 strokeChart];
}

//隐藏tabbar
-(void)viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.scrollView];
    
    self.scrollView.contentSize = CGSizeMake(0, 900 + 20 + 30);
    
    //图表
    [self p_tubiao1];
    
    [self p_tubiao2];
    
    [self p_tubiao3];
}

#pragma mark - 图表——1.2.3
//1
- (void )p_tubiao1
{
    
    self.view_bg1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
    self.view_bg1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.view_bg1];
    
    
    self.lineChart1 = [[PNLineChart alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 270)];
    self.lineChart1.yLabelFormat = @"%d";
    self.lineChart1.backgroundColor = [UIColor clearColor];
    [self.view_bg1 addSubview:self.lineChart1];
    
    //7天数据 x轴
    [self.lineChart1 setXLabels:@[@"12.1",@"12.2",@"12.3",@"12.4",@"12.5",@"12.6",@"12.7"]];
    //是否显示 x轴
    self.lineChart1.showCoordinateAxis = YES;

    self.lineChart1.yFixedValueMax = 180;
    self.lineChart1.yFixedValueMin = 0;
    
    self.lineChart1.yLabelFont = [UIFont systemFontOfSize:10];
    [self.lineChart1 setYLabels:@[
                                 @"0",
                                 @"30",
                                 @"60",
                                 @"90",
                                 @"120",
                                 @"150",
                                 @"180",
                                 ]
     ];
    
    //线
    NSArray * data01Array = @[@33, @16, @26, @77, @186, @127, @176];
    PNLineChartData *data01 = [PNLineChartData new];
    data01.dataTitle = @"日访问量";
    data01.color = [UIColor orangeColor];
    data01.alpha = 0.3f;
    data01.itemCount = data01Array.count;
    data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
    data01.getData = ^(NSUInteger index) {
        CGFloat yValue = [data01Array[index] floatValue];
        return [PNLineChartDataItem dataItemWithY:yValue];
    };
    
    self.lineChart1.chartData = @[data01];
    [self.lineChart1 strokeChart];
    self.lineChart1.delegate = self;
    
    
    self.lineChart1.legendStyle = PNLegendItemStyleStacked;
    self.lineChart1.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    self.lineChart1.legendFontColor = [UIColor orangeColor];
    
    UIView *legend = [self.lineChart1 getLegendWithMaxWidth:200];
    [legend setFrame:CGRectMake(50, 10, 200, 30)];
    [self.lineChart1 addSubview:legend];
}


//2
- (void )p_tubiao2
{
    
    self.view_bg2 = [[UIView alloc] initWithFrame:CGRectMake(0, 300 + 10, SCREEN_WIDTH, 300)];
    self.view_bg2.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.view_bg2];
    
    
    self.lineChart2 = [[PNLineChart alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 270)];
    self.lineChart2.yLabelFormat = @"%d";
    self.lineChart2.backgroundColor = [UIColor clearColor];
    [self.view_bg2 addSubview:self.lineChart2];
    
    //1个月数据 x轴
    [self.lineChart2 setXLabels:@[@"12.1",@"12.6",@"12.11",@"12.16",@"12.21",@"12.26",@"12.31"]];
    //是否显示 x轴
    self.lineChart2.showCoordinateAxis = YES;
    
    self.lineChart2.yFixedValueMax = 360;
    self.lineChart2.yFixedValueMin = 0;
    
    self.lineChart2.yLabelFont = [UIFont systemFontOfSize:10];
    [self.lineChart2 setYLabels:@[
                                  @"0",
                                  @"70",
                                  @"140",
                                  @"210",
                                  @"280",
                                  @"350",
                                  @"420",
                                  ]
     ];
    
    //线
    NSArray * data01Array = @[@330, @160, @260, @177, @186, @127, @176];
    PNLineChartData *data01 = [PNLineChartData new];
    data01.dataTitle = @"5天访问量";
    data01.color = [UIColor brownColor];
    data01.alpha = 0.3f;
    data01.itemCount = data01Array.count;
    data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
    data01.getData = ^(NSUInteger index) {
        CGFloat yValue = [data01Array[index] floatValue];
        return [PNLineChartDataItem dataItemWithY:yValue];
    };
    
    self.lineChart2.chartData = @[data01];
    [self.lineChart2 strokeChart];
    self.lineChart2.delegate = self;
    
    
    self.lineChart2.legendStyle = PNLegendItemStyleStacked;
    self.lineChart2.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    self.lineChart2.legendFontColor = [UIColor brownColor];
    
    UIView *legend = [self.lineChart2 getLegendWithMaxWidth:200];
    [legend setFrame:CGRectMake(50, 10, 200, 30)];
    [self.lineChart2 addSubview:legend];
}

//3
- (void )p_tubiao3
{
    
    self.view_bg3 = [[UIView alloc] initWithFrame:CGRectMake(0, 600 + 20, SCREEN_WIDTH, 300)];
    self.view_bg3.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.view_bg3];
    
    
    self.lineChart3 = [[PNLineChart alloc] initWithFrame:CGRectMake(5, 15, SCREEN_WIDTH , 270)];
    self.lineChart3.yLabelFormat = @"%d";
    self.lineChart3.backgroundColor = [UIColor clearColor];
    [self.view_bg3 addSubview:self.lineChart3];
    
    //7天数据 x轴
    [self.lineChart3 setXLabels:@[@"1月",@"2月",@"3月",@"4月",@"5月",@"6月",@"7月",@"8月",@"9月",@"10月",@"11月",@"12月"]];
    //是否显示 x轴
    self.lineChart3.showCoordinateAxis = YES;
    
    self.lineChart3.yFixedValueMax = 2100;
    self.lineChart3.yFixedValueMin = 0;
    
    self.lineChart3.yLabelFont = [UIFont systemFontOfSize:9];
    [self.lineChart3 setYLabels:@[
                                  @"0",
                                  @"300",
                                  @"600",
                                  @"900",
                                  @"1200",
                                  @"1500",
                                  @"1800",
                                  @"2100",
                                  ]
     ];
    
    //线
    NSArray * data01Array = @[@330, @1600, @1016, @1770, @1860, @1270, @1760, @1330, @1600, @2016, @1770, @1860];
    PNLineChartData *data01 = [PNLineChartData new];
    data01.dataTitle = @"月访问量";
    data01.color = [UIColor redColor];
    data01.alpha = 0.3f;
    data01.itemCount = data01Array.count;
    data01.inflexionPointStyle = PNLineChartPointStyleTriangle;
    data01.getData = ^(NSUInteger index) {
        CGFloat yValue = [data01Array[index] floatValue];
        return [PNLineChartDataItem dataItemWithY:yValue];
    };
    
    self.lineChart3.chartData = @[data01];
    [self.lineChart3 strokeChart];
    self.lineChart3.delegate = self;
    
    
    self.lineChart3.legendStyle = PNLegendItemStyleStacked;
    self.lineChart3.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    self.lineChart3.legendFontColor = [UIColor redColor];
    
    UIView *legend = [self.lineChart3 getLegendWithMaxWidth:200];
    [legend setFrame:CGRectMake(50, 10, 200, 30)];
    [self.lineChart3 addSubview:legend];
}



#pragma mark - 点击方法
- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex
{

}

- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex
{

}


@end
